
var keyPara=[];
var keyValPara=[];

var param=[];
var valParam=[];

var evaTime=[], evaGood=[],evaTotal=[],evaBad=[],avaMedium=[];
$(function(){

    getDate();
    function getDate(){
        $.ajax({
            type: "post",
            url: "/demo/saleDate",
            cache:false,
            async:false,
            dataType: "json",
            success: function(data){
                var list = data;
                if(list.length>0){
                    for(var i =0; i<list.length; i++){
                        var para = list[i];
                        keyPara.push(para.key);

                        var keyMap = {value:para.count, name:para.key}
                        keyValPara.push(keyMap);
                    }
                }

            }

        });
    }



    //初始化echarts
    var myChart = echarts.init(document.getElementById("mains"));
    //配置图标
    option = {
        title : {
            text: '促销方式分布图',
            subtext: '数据来源京东',
            x:'center'
        },
        color:['#c23531','#2f4554', '#61a0a8', '#d48265', '#91c7ae','#749f83',  '#ca8622', '#bda29a','#6e7074', '#546570', '#c4ccd3','#3398DB'],
        tooltip : {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
            orient: 'vertical',
            left: 'left',
            data: keyPara
        },
        series : [
            {
                name: '访问来源',
                type: 'pie',
                radius : '55%',
                center: ['50%', '60%'],
                data:keyValPara,
                itemStyle: {
                    emphasis: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };

    //使用指定配置项和数据显示图表
    myChart.setOption(option);



    getPriceDate();
    function getPriceDate(){
        $.ajax({
            type: "post",
            url: "/demo/getPriceCount",
            cache:false,
            async:false,
            dataType: "json",
            success: function(data){
                var list = data;
                if(list.length>0){
                    for(var i =0; i<list.length; i++){
                        var para = list[i];
                        param.push(para.key);
//                           var keyMap = {value:para.count, name:para.key}
                        valParam.push(para.count);
                    }
                }

            }

        });
    }

    var myChartPrice = echarts.init(document.getElementById("main2"));

    optionPrice = {
        title : {
            text: '价格区间图'
        },
        color: ['#3398DB'],
        tooltip : {
            trigger: 'axis',
            axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis : [
            {
                type : 'category',
                data : param,
                axisTick: {
                    alignWithLabel: true
                }
            }
        ],
        yAxis : [
            {
                type : 'value'
            }
        ],
        series : [
            {
                name:'价格',
                type:'bar',
                barWidth: '60%',
                data:valParam
            }
        ]
    };
    //使用指定配置项和数据显示图表
    myChartPrice.setOption(optionPrice);




    getEvaluate();
    function getEvaluate(){
        $.ajax({
            type: "post",
            url: "/demo/getEvaluate",
            cache:false,
            async:false,
            dataType: "json",
            success: function(data){
                var list = data;
                if(list.length>0){
                    for(var i =0; i<list.length; i++){
                        var para = list[i];
                        evaTime.push(para.time);
                        evaTotal.push(para.total);
                        evaGood.push(para.good);
                        avaMedium.push(para.medium);
                        evaBad.push(para.bad);;
                    }
                }

            }

        });
    }

    var myChartEvaluate = echarts.init(document.getElementById("main3"));

    optionEvaluate = {
        title: {
            text: '评论趋势图',
            subtext: ''
        },
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data:['好评','中评','差评']
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        toolbox: {
            feature: {
                saveAsImage: {}
            }
        },
        calculable : true,
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: evaTime
        },
        yAxis: {
            type: 'value'
        },
        series: [
            // {
            //     name:'总评',
            //     type:'line',
            //     data:evaTotal
            // },
            {
                name:'好评',
                type:'line',
                data:evaGood
            },
            {
                name:'中评',
                type:'line',
                data:avaMedium
            },
            {
                name:'差评',
                type:'line',
                data:evaBad
            }

        ]
    };
    //使用指定配置项和数据显示图表
    myChartEvaluate.setOption(optionEvaluate);


});

